<?php
namespace app\shop\controller;
use think\Controller;
use think\request;
use think\Db;
use app\service\appletService;
use app\service\roominfoService;
class Fetchdata extends Controller{
    public function index(){
        $community=Db::table("community")->order('sort')->select();
        $this->assign("community",$community);
        return $this->fetch();
    }
    public function details(){
        $room_id=request()->param("roomid");
        $commnuity_id=request()->param("community_id");
        $roominfo=(new roominfoService())->roominfoIdList($room_id);
        //echo "<pre>";
        //var_dump($roominfo);
        $commnuity=(new roominfoService())->communityIdName($commnuity_id);
        $billlis = (new appletService())->billRoomIdList($roominfo['out_room_id']);
        //var_dump($billlis);die;
        if(empty($billlis)){
            return $this->fetch("bill/nopaymsg");
        }
        $billlist = (new appletService())->cost_type($roominfo['out_room_id']);
        
        /*foreach ($billlist as $b){
            $lis[] = (new appletService())->select($userinfo['out_room_id'],$b);
        }*/
        $roominfo=Db::table("roominfo")->where("out_room_id",$roominfo["out_room_id"])->find();
        //var_dump($roominfo);die;
        $this->assign("commnuity",$commnuity);
        $this->assign("billlist",$billlis);
        $this->assign("roominfo",$roominfo);
        return $this->fetch();
    }
	public function getgroup(){
        $communityid=request()->param("communityid");
        $group=Db::table('roominfo')->distinct(true)->field('zz_group')->where("community_id",$communityid)->select();
        $str="<option value=''>请选择组团</option>";
        foreach ($group as $key => $value) {
           $str=$str."<option value='".$value["zz_group"]."'>".$value["zz_group"]."</option>";
        }
        echo $str;
    }

    public function getbuilding(){
        $communityid=request()->param("communityid");
        $group=request()->param("group");
        $building=Db::table('roominfo')->distinct(true)->field('building')->where("community_id",$communityid)->where("zz_group",$group)->select();
        /*if(empty($group)){
            $building=Db::table('roominfo')->distinct(true)->field('building')->where("community_id",$communityid)->select();
        }*/
        $str="<option value=''>请选择幢号</option>";
        foreach ($building as $key => $value) {
           $str=$str."<option value='".$value["building"]."'>".$value["building"]."</option>";
        }
        echo $str;
    }
    public function getunit(){
        $communityid=request()->param("communityid");
        $group=request()->param("group");
        $building=request()->param("building");
        $unit=Db::table('roominfo')->distinct(true)->field('unit')->where("community_id",$communityid)->where("zz_group",$group)->where("building",$building)->select();
        /*if(empty($group)){
           $unit=Db::table('roominfo')->distinct(true)->field('unit')->where("community_id",$communityid)->where("building",$building)->select();
        }*/
        $str="<option value=''>请选择单元</option>";
        foreach ($unit as $key => $value) {
           $str=$str."<option value='".$value["unit"]."'>".$value["unit"]."</option>";
        }
        echo $str;
    }
    public function getroomid(){
        $communityid=request()->param("communityid");
        $group=request()->param("group");
        $building=request()->param("building");
        $unit=request()->param("unit");
        $roomid=Db::table('roominfo')->field('id,room')->where("community_id",$communityid)->where("zz_group",$group)->where("building",$building)->where("unit",$unit)->select();
        /*if(empty($group)){
           $roomid=Db::table('roominfo')->field('id,room')->where("community_id",$communityid)->where("building",$building)->where("unit",$unit)->select();
        }*/
        $str="<option value=''>请选择房间号</option>";
        foreach ($roomid as $key => $value) {
           $str=$str."<option value='".$value["id"]."'>".$value["room"]."</option>";
        }
        echo $str;
    }
}